/*
 * Copyright (C) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#ifndef CLIPPATHVIEWNONENODE_H
#define CLIPPATHVIEWNONENODE_H

#pragma once

#include "RNOH/arkui/ArkUINode.h"
#include <native_drawing/drawing_matrix.h>
#include <native_drawing/drawing_pen.h>
#include <native_drawing/drawing_rect.h>
#include <native_drawing/drawing_types.h>
#include "ClipPathProps.h"
#include "SVGViewBox.h"
namespace rnoh {
struct CanvasCallback {
    std::function<void(ArkUI_NodeCustomEvent *event)> callback;
};

class ClipPathViewNoneNode : public ArkUINode {
public:
    ClipPathViewNoneNode();
    ~ClipPathViewNoneNode() override;
    void InsertChild(ArkUINode &child, std::size_t index);
    void RemoveChild(ArkUINode &child);
    void SetD(const std::string d);
    void SetStrokeWidth(float const width);
    void SetStrokeCap(std::string const cap);
    void SetStrokeJoin(std::string const join);
    void SetStrokeMiter(float const miter);
    void SetStrokeStart(float const start);
    void SetStrokeEnd(float const end);
    void SetViewBox(std::vector<float> viewBox);
    void SetAlign(std::string v);
    void SetAspect(std::string v);
    void SetFillRule(std::string v);
    // transFrom
    void SetTransX(float v);
    void SetTransY(float v);
    void SetTransPercentageValue(bool v);
    void SetRot(float v);
    void SetRotO(float v);
    void SetRotOx(float v);
    void SetRotOy(float v);
    void SetRotPercentageValue(bool v);
    void SetSc(float v);
    void SetScX(float v);
    void SetScY(float v);
    void SetScO(float v);
    void SetScOx(float v);
    void SetScOy(float v);
    void SetTranslateZ(float z);
    void SetScPercentageValue(bool v);

private:
    void (*eventReceiver)(ArkUI_NodeCustomEvent *event);
    void OnDraw(ArkUI_NodeCustomEvent *event);
    void setupPath(OH_Drawing_Canvas *canvas);
    void viewBoxTransform();
    bool validateViewBox();
    void setRect(OH_Drawing_Rect *target, OH_Drawing_Rect *src);
    void setRectF(OH_Drawing_Rect *target, float left, float top, float right, float bottom);
    void setPaintStrokeProps();
    float toDip(float value);
    void canvasTransform();
    void drawPath(OH_Drawing_Canvas *canvas);
    void setPanStyleMode(OH_Drawing_Canvas *canvas, int type);

private:
    std::string mD{ "" };
    std::string mAlign{ "xMinYMin" };
    CanvasCallback *canvasCallback_{ nullptr };
    int mAspect{ SVGViewBox::MOS_MEET };
    ClipPathProps *mProps{ new ClipPathProps() };
    OH_Drawing_Rect *mRectVb{ OH_Drawing_RectCreate(0.0f, 0.0f, -1.0f, -1.0f) };
    OH_Drawing_Rect *mRectVbDensity{ OH_Drawing_RectCreate(0.0f, 0.0f, -1.0f, -1.0f) };
    OH_Drawing_Rect *mRectPath{ OH_Drawing_RectCreate(0.0f, 0.0f, 0.0f, 0.0f) };
    OH_Drawing_Rect *mBounds{ OH_Drawing_RectCreate(0.0f, 0.0f, 0.0f, 0.0f) };
    OH_Drawing_Matrix *mMatrix{ OH_Drawing_MatrixCreate() };
    OH_Drawing_Path *mPath{};
    OH_Drawing_Path *mPath2{ OH_Drawing_PathCreate() };
    OH_Drawing_Pen *mPaint{ OH_Drawing_PenCreate() };
    OH_Drawing_Pen *mPaintStroke{ OH_Drawing_PenCreate() };
    OH_Drawing_Canvas *canvas{ nullptr };
    float mTranslationX{ 0.0f };
    float mTranslationY{ 0.0f };
    bool mTranslationIsPercent{ false };
    float mRotation{ 0.0f };
    float mRotationOx{ 0.0f };
    float mRotationOy{ 0.0f };
    bool mRotationIsPercent{ false };
    float mScaleX{ 1.0f };
    float mScaleY{ 1.0f };
    float mScaleOriginX{ 0.0f };
    float mScaleOriginY{ 0.0f };
    bool mScaleIsPercent{ false };
};
} // namespace rnoh

#endif